package com.tanhua.admin.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.bilibili.model.db.Log;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * @author HuangRongFu
 * 2021/11/29 星期一9:39 下午
 */


public interface LogMapper extends BaseMapper<Log> {

    //今日新增用户
    @Select("SELECT COUNT(1) FROM tb_log where log_time = #{today} and type = '0101';")
    Integer countNumRegisteredToday(String today);

    //每日活跃用户
    @Select("SELECT COUNT(DISTINCT user_id) FROM tb_log WHERE log_time = #{today} ;")
    Integer countNumActiveByDate(String today);

    //登录次数
    @Select("SELECT COUNT(1) from tb_log where log_time = #{today} and type = '0102';")
    Integer countNumLoginByDate(String today);

    //次日留存用户
//    @Select("SELECT COUNT(DISTINCT today.user_id) from " +
//            "(SELECT user_id FROM tb_log WHERE log_time = '2021-11-30' and type = '0101')  today," +
//            "(SELECT DISTINCT user_id FROM tb_log WHERE log_time = '2021-11-29' ) yesterday " +
//            "WHERE yesterday.user_id = today.user_id;")
    @Select("select count(distinct user_id) from tb_log where log_time=#{yesterday} and type='0101' and user_id in (" +
            " select distinct user_id from tb_log where log_time=#{today})")
    Integer countNumRetention1d(@Param("today") String today,@Param("yesterday") String yesterday);

    @Select("select count(distinct user_id) from tb_log where log_time > #{date}")
    Long countAfterDate(String date);

}
